<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>FOr循环优化</title>
</head>
<body>
    <p class="btn">add</p>
    <p class="btn">add</p>
    <p class="btn">add</p>
    <p class="btn">add</p>
    <p class="btn">add</p>
    <p class="btn">add</p>
    <p class="btn">add</p>
    <p class="btn">add</p>
    <p class="btn">add</p>
    <p class="btn">add</p>

    <script>
        var aBtns = document.getElementsByClassName('btn')

        // 每次使用仍需要重新对length进行获取
        for (var i = 0; i< aBtns.length; i++) {
            console.log(i);
        }

        // 每次使用不需要重新对len进行获取
        for (var i = 0, len = aBtns.length; i< len; i++) {
            console.log(i);
        }
    </script>
</body>
</html>